﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using System.Text;
//librerias especiales para la BD
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Data.SqlTypes;

namespace CityGames
{
    public class CADTarifa
    {

        /*******************************Funciones de Mirellys***********************************************/
        static private DSTarifasTableAdapters.TarifasTA tarifasTA = new DSTarifasTableAdapters.TarifasTA();
        static private string cadConexion = System.Configuration.ConfigurationManager.ConnectionStrings["CityGames.Properties.Settings.BDCityGamesConnectionString"].ConnectionString;

        public DataTable getTarifas()
        {

            DataTable resultado = new DataTable();
            try
            {
                resultado = tarifasTA.GetData();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return resultado;
        }

        public DataSet ObtenerTarifas()
        {
            DataSet resultado = new DataSet();
     
            try
            {
                SqlConnection conexion = new SqlConnection(cadConexion);
                string select = "SELECT * FROM Tarifa ORDER BY Categoria";
                SqlCommand comandoSql = new SqlCommand(select, conexion);
                SqlDataAdapter da = new SqlDataAdapter(comandoSql);

                da.Fill(resultado, "Tarifas");
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return resultado;
        }

        public bool ModificarTarifas(DataSet dsTarifas, string nombreTabla)
        {
            bool resultado = false;
            string select = "SELECT Categoria, NumeroDias, Precio, Recargo FROM Tarifa ORDER BY Categoria";

            try
            {
                SqlConnection conexion = new SqlConnection(cadConexion);
                SqlDataAdapter da = new SqlDataAdapter(select, conexion);
                SqlCommandBuilder cb = new SqlCommandBuilder(da);
                da.Update(dsTarifas,nombreTabla);

                resultado = true; 
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return resultado;
        }
    }
}
